﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;
namespace IFRS.DataAccess.DAL
{
    public class SPR_GSBBond
    {
        public DataTable SEARCH_ALL(GSBBond gSBBond, Paging paging, bool IFRS_ALLBRANCH, string sIFRS_COST_CENTER, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@isAllBranch", IFRS_ALLBRANCH));
                lstParams.Add(new SqlParameter("@sCostCenter", sIFRS_COST_CENTER));
                lstParams.Add(new SqlParameter("@TransactionDate", gSBBond.TransactionDate.AsDBValue()));               
                lstParams.Add(new SqlParameter("@CostCenter", gSBBond.CostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", gSBBond.IsConfirmed.AsDBValue()));

                dt = Utility.StoredProcDataTable("SPR_GSBBond_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable SEARCH_BYID(int GSBBondID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@GSBBondID", GSBBondID.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_GSBBond_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(GSBBond gSBBond)
        {

            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@GSBBondID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@TransactionDate", gSBBond.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@BondNo", gSBBond.BondNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@CostCenter", gSBBond.CostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@GLAccount", gSBBond.GLAccount.AsDBValue()));
                lstParams.Add(new SqlParameter("@StartedDate", gSBBond.StartedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@EndDate", gSBBond.EndDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@DayCountMethodID", gSBBond.DayCountMethodID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentDateID", gSBBond.PaymentDateID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentFreq", gSBBond.PaymentFreq.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentFreqTimeBase", gSBBond.PaymentFreqTimeBase.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentConditionID", gSBBond.PaymentConditionID.AsDBValue()));
                lstParams.Add(new SqlParameter("@CurrencyCode", gSBBond.CurrencyCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@BondValue", gSBBond.BondValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountValue", gSBBond.AccountValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@EmbeddedOptionID", gSBBond.EmbeddedOptionID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PriceValueUnitID", gSBBond.PriceValueUnitID.AsDBValue()));
                lstParams.Add(new SqlParameter("@LicenseStatusID", gSBBond.LicenseStatusID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PriceValue", gSBBond.PriceValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", gSBBond.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_GSB_PRDCD", gSBBond.RP_GSB_PRDCD.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_SOURCE_FILE", gSBBond.RP_SOURCE_FILE.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_MAPPING_CD", gSBBond.RP_MAPPING_CD.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedDate", gSBBond.CreatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBy", gSBBond.CreatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", gSBBond.CreatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBranch", gSBBond.CreatedBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", gSBBond.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", gSBBond.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", gSBBond.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", gSBBond.UpdatedBranch.AsDBValue()));

                Utility.ExecuteStoredProc("SPR_GSBBond_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(GSBBond gSBBond)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@GSBBondID", gSBBond.GSBBondID.AsDBValue()));
                lstParams.Add(new SqlParameter("@TransactionDate", gSBBond.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@BondNo", gSBBond.BondNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@CostCenter", gSBBond.CostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@GLAccount", gSBBond.GLAccount.AsDBValue()));
                lstParams.Add(new SqlParameter("@StartedDate", gSBBond.StartedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@EndDate", gSBBond.EndDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@DayCountMethodID", gSBBond.DayCountMethodID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentDateID", gSBBond.PaymentDateID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentFreq", gSBBond.PaymentFreq.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentFreqTimeBase", gSBBond.PaymentFreqTimeBase.AsDBValue()));
                lstParams.Add(new SqlParameter("@PaymentConditionID", gSBBond.PaymentConditionID.AsDBValue()));
                lstParams.Add(new SqlParameter("@CurrencyCode", gSBBond.CurrencyCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@BondValue", gSBBond.BondValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountValue", gSBBond.AccountValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@EmbeddedOptionID", gSBBond.EmbeddedOptionID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PriceValueUnitID", gSBBond.PriceValueUnitID.AsDBValue()));
                lstParams.Add(new SqlParameter("@LicenseStatusID", gSBBond.LicenseStatusID.AsDBValue()));
                lstParams.Add(new SqlParameter("@PriceValue", gSBBond.PriceValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", gSBBond.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedDate", gSBBond.CreatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBy", gSBBond.CreatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", gSBBond.CreatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBranch", gSBBond.CreatedBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", gSBBond.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", gSBBond.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", gSBBond.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", gSBBond.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_GSBBond_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(GSBBond gSBBond)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@GSBBondID", gSBBond.GSBBondID.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", gSBBond.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", gSBBond.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", gSBBond.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", gSBBond.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_GSBBond_DELETE", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}
